int safe_query(ConnectionPool *pool, const char *query, MYSQL_RES **result) {
	    int retry = 0;
	        MYSQL *conn = NULL;
		    
		    while (retry < 3) {
			            conn = pool_get_connection(pool);
				            if (!conn) return -1; // 获取连接失败
					            
					            if (mysql_query(conn, query) == 0) {
							                *result = mysql_store_result(conn);
									            pool_release_connection(pool, conn);
										                return 0; // 成功
												        }
						            

						            if (mysql_errno(conn) == CR_SERVER_GONE_ERROR) {
								                mysql_close(conn);
										            conn = mysql_init(NULL); // 重建连接
											                retry++;
													        } else {
															            break; // 非连接错误直接退出
																            }
							        }
		        
		        pool_release_connection(pool, conn);
			    return -1; // 失败
}
